package com.zzzzzz.core.web;

import java.text.SimpleDateFormat;

import javax.annotation.Resource;

import com.zzzzzz.account.model.Ticket;
import com.zzzzzz.account.service.TicketService;
import com.zzzzzz.account.service.UserService;
import com.zzzzzz.common.util.Validator;

public class BaseController {

	@Resource(name="userService")
	private UserService userService;

	@Resource(name="ticketService")
	private TicketService ticketService;
	
	protected boolean isSignedIn(){
		return userService.isSignedIn();
	}

	protected Ticket getTicket(String token, String type) {
		if (Validator.isNull(token)) {
			return null;
		}
		try {
			Ticket ticket = ticketService.findByKeyAndType(token, type);
			return ticket;
			
		}catch (Exception e) {
			// do nothing
		}
		return null;
	}
	
	public SimpleDateFormat format = new SimpleDateFormat("MMM dd, yyyy 'at' hh:mm a");
}
